{extend name="shop/default/Member/base" /}
{block name="resources"}
<!-- 添加css、字体文件文件 -->

{/block}
{block name="main"}
<div class="user-right">
	<div class="box">
		<script type="text/javascript" src="js/region.js"></script>
		<script type="text/javascript" src="js/shopping_flow.js"></script> 
		<div class="tabmenu">
			<ul class="tab pngFix">
				<li class="first active">新增收货地址</li>
			</ul>
		</div>
		<div class="alert alert-success">
			<h4>操作提示：</h4>
			<ul>
				<li>您可对已有的地址进行编辑及删除，亦可新增收货地址</li>
			</ul>
		</div>
		<input type="hidden" id="adressid" value="{$address_id}" />
		<input type="hidden" id="hidUrl" value="" />
		<input type="hidden" id="provinceid" value="-1" />
		<input type="hidden" id="cityid" value="-1" />
		<input type="hidden" id="districtid" value="-1" />
		<input type="hidden" value="-1" id="AddressID">
		<div class="mar_top">
		<form action="" method="post" name="theForm">
			<table width="100%" border="0" cellpadding="10" cellspacing="1" bgcolor="#eeeeee">
				<tr>
					<td align="right" width="10%">配送区域：</td>
					<td colspan="3" align="left">
						<select name="province" id="seleAreaNext" onchange="GetProvince();getSelCity();">
							<option value="">请选择省</option>
						</select>
						<select name="city" id="seleAreaThird" onchange="getSelCity();">
							<option value="">请选择市</option>
						</select>
						<select name="district" id="seleAreaFouth">
							<option value="-1">请选择区</option>
						</select>
						(必填)
					</td>
				</tr>
				<tr>
					<td align="right" width="10%">收货人姓名：</td>
					<td align="left" width="40%"><input name="consignee" type="text" class="inputBg" id="Name" value="" />(必填) </td>
				</tr>
				<tr>
					<td align="right">详细地址：</td>
					<td align="left" colspan="3"><input name="address" type="text" class="inputBg" id="AddressInfo" value="" style="width: 692px;"/>(必填)</td>
				</tr>
				<tr>
					<td align="right">手机：</td>
					<td align="left"><input name="mobile" type="text" class="inputBg" id="Moblie" value="" />(必填)</td>
				</tr>
				<tr>
					<td colspan="4" align="center"><input type="button" name="button" class="main-btn main-btn-large"  value="新增收货地址" onclick="saveAddress()"/></td>
				</tr>
			</table>
		</form>
		<div class="blank10"></div>
		</div>
	</div>
</div>
{/block}
{block name="javascript"}
<script src="__TEMP__/{$style}/public/js/address.js"></script>
<script type="text/javascript">
$(function() {
	var selCity = $("#seleAreaNext")[0];
	for (var i = selCity.length - 1; i >= 0; i--) {
		selCity.options[i] = null;
	}
	var opt = new Option("请选择省", "-1");
	selCity.options.add(opt);
	// 添加省
	$.ajax({
		type : "post",
		url : "getprovince",
		dataType : "json",
		success : function(data) {
			if (data != null && data.length > 0) {
				for (var i = 0; i < data.length; i++) {
					var opt = new Option(data[i].province_name,
							data[i].province_id);
					selCity.options.add(opt);
				}
				$("#seleAreaNext").val($("#provinceid").val());
			}
		}
	});
	
	var address_id = $("#adressid").val();
	if (address_id != 0) {
		// 查询这个收货地址的详细地址
		$.ajax({
			type : "post",
			url : "member_address_info_select",
			dataType : "json",
			data : {
				"address_id" : address_id
			},
			success : function(data) {
				var address_info = data["data"][0][0];
				var consigner = address_info["consigner"];
				var mobile = address_info["mobile"];
				var province = address_info["province"];
				var city = address_info["city"];
				var district = address_info["district"];
				var address = address_info["address"];
				$("#Name").val(consigner);
				$("#Moblie").val(mobile);
				$("#AddressInfo").val(address);
				$("#seleAreaNext").val(province);
				$("#provinceid").val(province);
				$("#cityid").val(city);
				$("#districtid").val(district);
				// 加载市
				var selCity = $("#seleAreaThird")[0];
				for (var i = selCity.length - 1; i >= 0; i--) {
					selCity.options[i] = null;
				}
				var opt = new Option("请选择市", "-1");
				selCity.options.add(opt);
				$.ajax({
					type : "post",
					url : "getcity",
					dataType : "json",
					data : {
						"ID" : province
					},
					success : function(data) {
						if (data != null && data.length > 0) {
							for (var i = 0; i < data.length; i++) {
								var opt = new Option(data[i].CityName, data[i].cityId);
								selCity.options.add(opt);
							}
							$("#seleAreaThird").val(city);
						}
					}
				});
				// 加载区县
				var selArea = $("#seleAreaFouth")[0];
				for (var i = selArea.length - 1; i >= 0; i--) {
					selArea.options[i] = null;
				}
				var opt = new Option("请选择市", "-1");
				selArea.options.add(opt);
				$.ajax({
					type : "post",
					url : "area",
					dataType : "json",
					data : {
						"ID" : city
					},
					success : function(data) {
						if (data != null && data.length > 0) {
							for (var i = 0; i < data.length; i++) {
								var opt = new Option(data[i].DistrictName, data[i].districtId);
								selArea.options.add(opt);
							}
							$("#seleAreaFouth").val(district);
						}
					}
				});
			}
		});
	}
});
</script>
{/block}